<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JsBench - Help</title>
<link href="style.css" rel="stylesheet" type="text/css">
<!-- CSS from Google Docs. -->
<style>
div, address, ol, ul, li, option, select { 
  margin-top: 0px;
  margin-bottom: 0px;
}
p {
  margin: 0px;
}
h3 { font-size: 13pt }
h2 { font-size: 14pt }
h1 { font-size: 16pt }
</style>
</head>
<body>
<table align=center border=0 cellpadding=0 cellspacing=0>
<tr height=6>
<td height=6 width=6 class="corner"></td>
<td height=6 class="border"></td>
<td height=6 width=6 class="corner" style="background-position:-6px 0"></td>
</tr>
<tr>
<td width=6 class=border></td>
<td id="mainTD">
<form onsubmit="return false">
<div id="contentDiv">
<div style="float:right"><a href="/">Home</a></div>
<span id="headerElem">JsBench - Help</span>
<div id="suiteDiv">




<h3 id=rr4t0>
  Getting Started

</h3>
Typically you want to sign in first. This allows your Benchmarking Suites to be
automatically saved and gives you the ability to share them with others. If you
are not signed in, your Suite will be lost when you leave the page.<br id=r0:e0>
<br id=a-q:0>
<ol id=q4rk0>
  <li id=q4rk1>
    Start by selecting "New Suite" from the dropdown box.
  </li>
  <li id=q4rk2>
    Create two or more functions to be compared in this Suite. Give them
    descriptive names, this is how they will be identified in the graph.
  </li>
  <li id=q4rk3>

    Functions may accept named parameters. Parameters are passed to the function
    by specifying an array of literals in the "Function Parameters" text box.
  </li>
  <li id=q4rk3>
    Enter a reasonable number of iterations. This should be set such that the
    total runtime for each benchmark is at least an order of magnitude greater
    than the operating system's timer resolution, but small enough so that it
    does not trigger the "slow script" warning. On windows, the timer resolution
    is about 10ms and the slow script warning is displayed after 10s, so you
    probably want to have a run time of 100ms-1s.
  </li>
  <li id=q4rk3>
    Finally, click "Run All Benchmarks" to see the results. Your Suite may be
    shared with others by copy/pasting the URL.
  </li>
  <li id=q4rk3>
    Times for the top 3 browsers will be displayed along with your current run.<br id=lk1_0>

  </li>
</ol>
<h3 id=rlmb2>
  Examples
</h3>
<span id=z-o20><b>Type Conversions</b></span><br id=oy.20>
Demonstrates various type conversion techniques:<br id=oy.21>
Boolean:
<a href=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRiaAgw id=mh2o title=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRiaAgw>http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRiaAgw</a><br id=s6sn0>
String:
<a href=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRiuAgw id=ct2_ title=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRiuAgw>http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRiuAgw</a><br id=z-o21>

<br id=abdl0>
<span id=moz20><b>Build Array</b></span><br id=abdl1>
Demonstrates techniques faster than the Array.push() method:<br id=ev870>
<a href=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRj2Aww id=f3k1 title=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRj2Aww>http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRj2Aww</a><br id=f2.e0>
<br id=xw_10>
<span id=xw_11><b>Math Library vs. Operators </b></span><br id=xw_12>
Demonstrates how using operators is faster than the Math library:<br id=xw_13>
Math.ceil:
<a href=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjOAQw id=yk15 title=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjOAQw>http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjOAQw</a><br id=dfpc0>
Math.floor:
<a href=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjRAQw id=avt3 title=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjRAQw>http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjRAQw</a><br id=hz4l0>

<br id=hz4l1>
<span id=hz4l2><b>Loops</b></span><br id=hz4l3>
Demonstrates the wild inefficiency of for-in loops:<br id=hz4l4>
<a href=http://www.jsbench.com/#suite=agdqc2JlbmNocgsLEgVTdWl0ZRgNDA id=sb9o title=http://www.jsbench.com/#suite=agdqc2JlbmNocgsLEgVTdWl0ZRgNDA>http://www.jsbench.com/#suite=agdqc2JlbmNocgsLEgVTdWl0ZRgNDA</a><br id=sqex0>
<br id=sqex1>
<span id=sqex2><b>Property Caching</b></span><br id=sqex3>
Demonstrates the benefit of caching properties:<br id=sqex4>
<a href=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjoAQw id=e33r title=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjoAQw>http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjoAQw</a><br id=sqex5>
<br id=sqex6>
<span id=rrby0><b>String Concatenation</b></span><br id=u38w0>

Demonstrates how the popular Array.join method of concatenating strings is a big
win in IE, but neutral to a loss in FF:<br id=rrby1>
<a href=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjPAww id=a4ce title=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjPAww>http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjPAww</a><br id=hd280>
<br id=hd281>
<span id=hd282><b>Variable Declarations</b></span><br id=hd283>
Demonstrates the importance of variable declaration:<br id=hd284>
<a href=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjqAgw id=ogiw title=http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjqAgw>http://www.jsbench.com/#suite=agdqc2JlbmNocgwLEgVTdWl0ZRjqAgw</a>
<h3 id=rr4t0>
  Timing Methodology
</h3>
Each test method is executed in a loop which runs the specified number of
iterations. To obtain the reported time, the total amount of time spent on all
iterations is divided by the number of iterations.&nbsp; This allows for
precision much greater than the default ~10-15ms resolution available on Windows
machines. Here's the critical loop:<br id=cseu0>

<font color=#38761d id=u2u40><span id=u2u41 style="FONT-FAMILY:Courier New"><br id=u2u42>
&nbsp;&nbsp;&nbsp; startTime = new Date().getTime();
</span><br id=u2u43 style="FONT-FAMILY:Courier New">
<span id=u2u44 style="FONT-FAMILY:Courier New">&nbsp;&nbsp;&nbsp; for (; i &gt;
0; --i) {</span><br id=u2u45 style="FONT-FAMILY:Courier New">
<span id=u2u46 style="FONT-FAMILY:Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
f.apply(window, p);</span><br id=u2u47 style="FONT-FAMILY:Courier New">
<span id=u2u48 style="FONT-FAMILY:Courier New">&nbsp;&nbsp;&nbsp;
}</span><br id=u2u49 style="FONT-FAMILY:Courier New">
<span id=u2u410 style="FONT-FAMILY:Courier New">&nbsp;&nbsp;&nbsp; endTime = new
Date().getTime();<br id=u2u411>

</span></font><br id=u2u412>
Notice that the function is called from the window object instead of directly.
This ensures the call object will not vary across benchmarks.&nbsp; Even though
a very efficient looping structure is used, there is still some overhead due to
the this and the function calls themselves. To compensate, before each suite is
run, an empty method is run for the number of iterations and its time is
subtracted from each reported time.<br id=nz.q0>
<br id=nz.q1>
Finally, as you are probably aware, garbage collection can be a significant
factor in JavaScript execution time. To help ensure its affect is consistent,
the framework sleeps for 150ms between each run to give the garbage collector
time to run. In IE,
<font color=#38761d id=u_6f0><span id=u_6f1 style="FONT-FAMILY:Courier New">CollectGarbage()</span></font>
is explicitly invoked before the sleep.<br id=llrc0>
<br id=llrc1>
To see the details for yourself, look at
<font color=#38761d id=q5wb0><span class=typ id=llrc2 style="FONT-FAMILY:Courier New">BenchmarkSuite</span><span class=pun id=llrc3 style="FONT-FAMILY:Courier New">.</span><span class=pln id=llrc4 style="FONT-FAMILY:Courier New">prototype</span><span class=pun id=llrc5 style="FONT-FAMILY:Courier New">.</span></font><span class=pln id=llrc6><font color=#38761d id=q5wb1><span id=q5wb2 style="FONT-FAMILY:Courier New">runAll</span></font>

and
<font color=#38761d id=q5wb3><span id=q5wb4 style="FONT-FAMILY:Courier New">Benchmark.prototype.run</span></font>
in
<a href=http://code.google.com/p/jsbench/source/browse/trunk/benchmark.js id=cyoj title=http://code.google.com/p/jsbench/source/browse/trunk/benchmark.js>
http://code.google.com/p/jsbench/source/browse/trunk/benchmark.js</a>.</span>

<br><br><br>

<center>
<a href="/">Back to benchmarking</a>
</center>

<br>


</div>
</div>
</td>
<td width=6 class=border></td>
<tr height=6>
<td height=6 width=6 class="corner" style="background-position:0 -6px"></td>
<td height=6 class="border"></td>
<td height=6 width=6 class="corner" style="background-position:-6px -6px"></td>
</tr>
</table>
<center>
<a href="http://code.google.com/appengine/">
<img src="/images/appengine.png" width="120" height="32"
     alt="Powered by Google AppEngine" border="0" vspace="5">
</a>
<br>
<a id="copyright" href="http://code.google.com/p/jsbench/">Open Source</a><br>
<span id="copyright">Copryright &copy; 2008 Tony Gentilcore</span></center>
</body>
</html>
